<?php
class NewsAction extends CommonAction {
	public function index() {
		//列表过滤器，生成查询Map对象
		$map = $this->_search();
		if ( method_exists( $this, '_filter' ) ) {
			$map = $this->_filter();
		}
		$map['mid'] = $this->mid;
		$model = D( $this->mod );
		if ( !empty( $model ) ) {
			$this->_list( $model, $map ,'top desc,iswelcome desc,ishelp desc, id desc');
		}
		cookie( '_currentUrl_', __SELF__ );
		$this->display();
		return;
    }
    public function _before_insert()
    {
    	$_POST['ctime'] = time();
    }


    public function _before_add()
    {
		$this->getThemes();
    }

    public function _before_edit()
    {
		$this->getThemes();
    }

    
    function getThemes()
    {
    	$dir = './Tpl/Mobile/';
    	$dir_handle = opendir($dir);
    	$arr=array();  
    	if($dir_handle)  
	    {  
	        // 这里必须严格比较，因为返回的文件名可能是“0”   
	        while(($file=readdir($dir_handle))!==false)  
	        {  
	            if($file==='.' || $file==='..' || strtolower($file)=='index' )  
	                continue;  
	            if(is_dir($dir.'/'.$file)){
	            	if(!is_file($dir.'/'.$file.'/news.html')) continue; 
	            	$v = array();
	                $v['tplname'] = $file;  
	                $v['preview'] = $dir.$file.'/news.jpg';  
	                $arr[] = $v;
	            }
	        }  
	        closedir($dir_handle);  
	    } 
	    $this->assign('tpllist',$arr);
    }
}